package com.woniuxy.springboot.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 佘赛飞
 * @create 2021 -10 -09 5:18 AM
 */
//对应拦截器类
public class LoginHandlerInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        Object username = request.getSession().getAttribute("username");
        if(username!=null){
            return true;
        }else {
            request.setAttribute("msg", "先登录");
            request.getRequestDispatcher("/index.html").forward(request, response);
            return false;
        }
    }
}
